package seven.servlet;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.context.ApplicationContext;
import seven.bean.model.MarketAdmin;
import seven.bean.vo.PageVo;
import seven.bean.vo.param.BaseListParam;
import seven.service.UserServiceImpl;
import seven.util.WordMap;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

@WebServlet("/admin/user/list")
public class UserServlet extends CommonServlet {
    UserServiceImpl userService;
    @Override
    public void init() throws ServletException {
        //给userService赋值
        ApplicationContext applicationContext= (ApplicationContext) getServletContext().getAttribute(WordMap.APPLICATION_CONTEXT);

        userService=applicationContext.getBean(UserServiceImpl.class);
    }


    protected void list(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException, InvocationTargetException, IllegalAccessException {
        //这个地方要使用service，service要从容器中得到
        //在这里要先注册一个全局的context
        //这个地方要先获取一下数据
        Map paramMap=req.getParameterMap();
        //然后用bean
        BaseListParam baseListParam=new BaseListParam();
        BeanUtils.copyProperties(baseListParam,paramMap);
        PageVo pageVo =userService.list(baseListParam);


        resp.getWriter().println();
    }
}
